@echo off
call :genProto trip
goto :EOF

:genProto
setlocal

set DOMAIN=%1
set PROTO_PATH=%DOMAIN%\api
echo %PROTO_PATH%
set GO_OUT_PATH=%DOMAIN%\api\gen\v1
echo %GO_OUT_PATH%
md %GO_OUT_PATH%

protoc --proto_path=%PROTO_PATH% --go_out %GO_OUT_PATH% --go_opt paths=source_relative --go-grpc_out %GO_OUT_PATH% --go-grpc_opt=paths=source_relative %DOMAIN%.proto

protoc --proto_path=%PROTO_PATH% --grpc-gateway_out %GO_OUT_PATH% --grpc-gateway_opt paths=source_relative --grpc-gateway_opt grpc_api_configuration=%PROTO_PATH%\%DOMAIN%.yaml %DOMAIN%.proto

set PBTS_BIN_DIR=..\wx\miniprogram\node_modules\.bin
echo %PBTS_BIN_DIR%
set PBTS_OUT_DIR=..\wx\miniprogram\service\proto_gen\%DOMAIN%
echo %PBTS_OUT_DIR%
md %PBTS_OUT_DIR%

%PBTS_BIN_DIR%\pbjs -t static -w es2020 %PROTO_PATH%\%DOMAIN%.proto --no-create --no-encode --no-decode --no-verify --no-delimited --force-number -o %PBTS_OUT_DIR%\%DOMAIN%_pb_tmp.js

echo 'import * as $protobuf from "protobufjs";\n' > $PBTS_OUT_DIR\%DOMAIN%_pb.js
type %PBTS_OUT_DIR%\%DOMAIN%_pb_tmp.js >> %PBTS_OUT_DIR%\%DOMAIN%_pb.js
del %PBTS_OUT_DIR\%DOMAIN%_pb_tmp.js
%PBTS_BIN_DIR%\pbts -o %PBTS_OUT_DIR%\%DOMAIN%_pb.d.ts %PBTS_OUT_DIR%\%DOMAIN%_pb.js

endlocal&goto :EOF